package com.presto.directo.mvvm.viewmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.presto.directo.entity.VersionEntity
import com.presto.directo.net.getHttpMap
import com.presto.directo.net.sign
import com.presto.directo.utils.*

class MainViewModel(application: Application) : BaseViewModel(application) {

    val versionLiveData = MutableLiveData<VersionEntity>()
    var showUpdate = false

    fun checkUpdate() {
        if (showUpdate) return
        start(onNext = {
            val versionEntity = getApiService().checkUpdate(getHttpMap().sign(3)).getResult()
            if (versionEntity.version_status.let { it == "1" || it == "2" }) {
                showUpdate = true
                versionLiveData.value = versionEntity
            }
        }, toast = false)
    }

}